package com.haixee.parkdemo.data_acl.mybatis;


import java.util.ArrayList;
import java.util.List;

/**
 * 请求上下文
 *
 * @author GUIFENG GUO
 * 2020/3/22 9:28
 */
public final class DataAclHolder {


    private static final ThreadLocal<Boolean> PROCESS_HOLDER = new ThreadLocal<>();

    public static void setProcess(Boolean process) {
        PROCESS_HOLDER.set(process);
    }

    public static Boolean getProcess() {
        return Boolean.TRUE.equals(PROCESS_HOLDER.get());
    }


    // ------------------------------ optUid ------------------------------------
    private static final ThreadLocal<Integer> OPT_UID_HOLDER = new ThreadLocal<>();

    public static void setOptUid(Integer uid) {
        OPT_UID_HOLDER.set(uid);
    }

    public static Integer getOptUid() {
        return OPT_UID_HOLDER.get();
    }



    // ------------------------------ job ------------------------------------
    private static final ThreadLocal<List<Integer>> JOB_LIST_HOLDER = new ThreadLocal<>();

    public static void setJobList(List<Integer> jobList) {
        JOB_LIST_HOLDER.set(jobList);
    }

    public static List<Integer> getJobList() {
        List<Integer> list = JOB_LIST_HOLDER.get();
        if (list == null) {
            return new ArrayList<>();
        }

        return list;
    }


    public static void remove() {
        OPT_UID_HOLDER.remove();
        JOB_LIST_HOLDER.remove();
        PROCESS_HOLDER.remove();
    }
}
